# 引入gtest模块
find_package(GTest CONFIG REQUIRED)

## ssh2协议远程连接库
#find_package(libtelnet REQUIRED)

find_package(Boost CONFIG REQUIRED
    COMPONENTS
        url
)

# cpp-httplib 网络请求
find_package(httplib REQUIRED)

# openssl加密算法库
# 设置OPENSSL的根目录
if (NOT DEFINED OPENSSL_ROOT_DIR)
    set(OPENSSL_ROOT_DIR /usr/local/lib64)
endif ()
# 从根目录寻找cmake配置文件
find_package(OpenSSL 3.5.1 EXACT CONFIG REQUIRED)
# 使用OPEN_SSL的静态库
if (OpenSSL_FOUND)
    set(OPENSSL_USE_STATIC_LIBS TRUE)
endif ()

# Boost库
find_package(Boost CONFIG REQUIRED
    COMPONENTS
#        format
#        circular_buffer
#        lockfree
        json
        asio
        system
)

# 为模块添加测试可执行文件
add_executable(database_tests
    database/file_db_holder_test.cpp
)
# 链接依赖项
target_link_libraries(database_tests
    PRIVATE
        spdlog::spdlog
        gperftools::tcmalloc
        GTest::gtest
        GTest::gtest_main
        ${PROJECT_NAME}::database
)
# 给模块增加预编译头文件
target_precompile_headers(database_tests
    PRIVATE
        ${PROJECT_INCLUDE_DIR}/pre_compiled.h
)
## 注册测试单元
#add_test(
#    NAME database_tests # Target名称
#    COMMAND $<TARGET_FILE:database_tests>
#)

# 观测探测模块测试
add_executable(probe_detect_tests
#    probe_detect/handle_https_probe_detect_test.cpp
#    probe_detect/handle_http_probe_detect_test.cpp
    probe_detect/handle_icmp_probe_detect_test.cpp
#    probe_detect/handle_udp_probe_detect_test.cpp
#    probe_detect/handle_tcp_probe_detect_test.cpp
)
# 连接依赖项
target_link_libraries(probe_detect_tests
    PRIVATE
        OpenSSL::SSL    # ssl/tls协议
        OpenSSL::Crypto # 加密算法
        httplib::httplib
        Boost::url
#        Boost::asio
#        Boost::system
#        asio2   # 网络框架
        GTest::gtest
        GTest::gtest_main
#        ${PROJECT_NAME}::logger
        ${PROJECT_NAME}::probe_detect
)
# 注册测试单元
#add_test(
#    NAME utils_tests # Target名称
#    COMMAND $<TARGET_FILE:utils_tests>
#)

# 观测探测模块测试
add_executable(probe_tests
    probe/handle_icmp_probe_task_test.cpp
    probe/handle_tcp_probe_task_test.cpp
)
# 连接依赖项
target_link_libraries(probe_tests
    PRIVATE
        gperftools::tcmalloc # 内存(池)分配器
        OpenSSL::SSL    # ssl/tls协议
        OpenSSL::Crypto # 加密算法
        asio2   # 网络框架
        bs_thread_pool # 线程池
        spdlog::spdlog
        GTest::gtest
        GTest::gtest_main
#        ${PROJECT_NAME}::probe_detect
)
# 给模块增加预编译头文件
target_precompile_headers(probe_tests
    PRIVATE
        ${PROJECT_INCLUDE_DIR}/pre_compiled.h
)
# 注册测试单元
#add_test(
#    NAME utils_tests # Target名称
#    COMMAND $<TARGET_FILE:utils_tests>
#)

# 备份测试模块测试
add_executable(backup_test_tests
    backup_test/handle_ssh_backup_test_test.cpp
    backup_test/handle_telnet_backup_test_test.cpp
)
# 连接依赖项
target_link_libraries(backup_test_tests
    PRIVATE
        GTest::gtest
        GTest::gtest_main
        ${PROJECT_NAME}::backup_test
)
# 注册测试单元
#add_test(
#    NAME utils_tests # Target名称
#    COMMAND $<TARGET_FILE:utils_tests>
#)

# 工具模块测试
add_executable(utils_tests
    utils/snowflake_uuid_generator_test.cpp
)
# 连接依赖项
target_link_libraries(utils_tests
    PRIVATE
        ${PROJECT_NAME}::utils
        GTest::gmock
        GTest::gmock_main
)
# 注册测试单元
#add_test(
#    NAME utils_tests # Target名称
#    COMMAND $<TARGET_FILE:utils_tests>
#)

# 包含Google Test的发现测试功能
include(GoogleTest)
# 使用gtest_discover_tests命令自动发现并运行unit_test_demo目标中的所有测试
gtest_discover_tests(
    database_tests
    probe_detect_test
    utils_tests
)

